<?php
/*
** 创意广告提交模板
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'home';
$return=array();
$return['basic']=$this->plugin_setting('basic');
if($_RQ['op']=='home'){
    
	$return['uniacid'] = $_SESSION['uniacid'];
	exi($return);
}
if($_RQ['op']=='minipost'){
	$postdata=get_postdata();
	$chatmsg = trim($postdata['msg']);
	$logid=$this->model('kefu')->addchatlog($chatmsg);
	$res['log']=array(
		'id'=>$logid,
		'mid'=>$_SESSION['uid'],
		'chatid'=>$_SESSION['chatid'],
		'askmsg'=>$chatmsg,
	);
	if($res['log'] && $res['log']['id']){
		if($return['basic']['pluginset']['iswenda']==1){
			exi('还有一个问题正在思考中，请稍后提问！','error');
		}
	}
	$params['key'] =  0;
	$params['logid'] =  $logid;
	$params['chatmsg'] =  $chatmsg;
	//exi('提交成功获取中...','success','jy_aixiaoyi/index');
	exi($params);
}
if($_RQ['op']=='getmsg'){
	$logid = trim($_RQ['logid']);
	$chatmsg = trim($_RQ['msg']);
	$res['key'] = intval($_RQ['key']);
	$res['msg']=$this->model('member')->bi_up();
	if(!$res['msg']){
		$res['msg']=$this->model('model')->getmsg($chatmsg);
	}
	if($res['msg'] && $res['msg']!='fail'){
		pdo_update('jy_aixiaoyi_msglog',array('answer'=>$res['msg']),array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
		$checkvip=$this->model('member')->checkvip('',true);
		if($checkvip!='isvip'){
			$basic=$this->plugin_setting('basic');
			$isgetfee=pdo_get('core_credit_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'plugin'=>'jy_aixiaoyi','tag'=>'bi_post'.$logid),'id');
			if(!$isgetfee){
				model('core/member')->member_credit($_SESSION['uid'],'credit3',$basic['bi_post'],false,'jy_aixiaoyi','提问消耗','bi_post'.$logid);
				model('core/member')->member_credit($_SESSION['uid'],'credit5',$basic['bi_jiankan'],true,'jy_aixiaoyi','提问获取健康币','bi_jiankan'.$logid);
			}
		}
	}
	if($res['msg']=='fail'){
		$res['fail']=1;
		$res['msg']='';
	}
	exi($res);
}